package io.union_pay.config;

import io.union_pay.client.UnionPayClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(UnionPayProperties.class)
@ConditionalOnProperty(prefix = "ucp", name = {"appid", "appkey", "mid", "tid", "url"})
public class UnionPayConfig {

    @Autowired
    private UnionPayProperties properties;

    @Bean
    public UnionPayClient client() {
        UnionPayClient client = new UnionPayClient();
        client.setProperties(properties);
        return client;
    }

}
